using System;
using System.IO;
using System.Xml.Serialization;

namespace Common.Tests
{
	public static class TestHelper
	{
		private static Random random;

		public static Random Random
		{
			get
			{
				if(random == null)
				{
					random = new Random();
				}

				return random;
			}
		}

		public static string RandomString
		{
			get { return Guid.NewGuid().ToString(); }
		}

		public static decimal RandomDecimal
		{
			get { return new decimal(Random.NextDouble()); }
		}

		public static DateTime RandomDateTime
		{
			get { return DateTime.Now.AddDays(Random.NextDouble()); }
		}

		public static string SerializeToXMLString<T>(object obj)
		{
			using (var stringWriter = new StringWriter())
			{
				var serializer = new XmlSerializer(typeof (T));
				serializer.Serialize(stringWriter, obj);
				return stringWriter.GetStringBuilder().ToString();
			}
		}
	}
}